package com.xscr.forum.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.xscr.forum.mapper.ForumImageMapper;
import com.xscr.forum.mapper.ForumReplyMapper;
import com.xscr.forum.po.ForumImage;
import com.xscr.forum.po.ForumReply;
import com.xscr.forum.service.ForumReplyService;
import com.xscr.mybatis.utility.PageBean;

public class ForumReplyServiceImpl implements ForumReplyService {

	@Autowired
	private ForumReplyMapper forumReplyMapper;
	
	@Override
	public int saveForumReply(ForumReply forumReply) throws Exception {
		return forumReplyMapper.insertSelective(forumReply);
	}

	@Override
	public int saveListForumReply(List<ForumReply> forumReply) throws Exception {
		return forumReplyMapper.insertListForumReply(forumReply);
	}

	@Override
	public int deleteForumReplyById(Integer id) throws Exception {
		ForumReply forumReply = new ForumReply();
		forumReply.setReplyId(id);
		forumReply.setStatus(-1);
		
		return forumReplyMapper.updateByPrimaryKeySelective(forumReply);
	}

	@Override
	public int updateForumReply(ForumReply forumReply) throws Exception {
		return forumReplyMapper.updateByPrimaryKeySelective(forumReply);
	}

	@Override
	public ForumReply findForumReplyById(Integer id) throws Exception {
		return forumReplyMapper.selectByPrimaryKey(id);
	}

	@Override
	public PageBean<ForumReply> findForumReplyByConditions(
			PageBean<ForumReply> pageBean) throws Exception {
		List<ForumReply> selectForumReplyListPage = forumReplyMapper.selectForumReplyListPage(pageBean);
		
		pageBean.setResult(selectForumReplyListPage);
		
		return pageBean;
	}

	@Override
	public List<ForumReply> findForumReplyByConditions(ForumReply forumReply)
			throws Exception {
		PageBean<ForumReply> pageBean = new PageBean<ForumReply>();
		
		pageBean.setParameter(forumReply);
			
		return forumReplyMapper.selectForumReplyListPage(pageBean);
	}
	
	@Override
	public List<ForumReply> findForumReplyByTopicId(Integer topicId)
			throws Exception {
		ForumReply forumReply=new ForumReply();
		forumReply.setTopicId(topicId);
		
		PageBean<ForumReply> pageBean = new PageBean<ForumReply>();
		
		pageBean.setParameter(forumReply);
			
		return forumReplyMapper.selectForumReplyListPage(pageBean);
	}

}
